//
//  WWSameSickVC.m
//  快医
//
//  Created by 孙博 on 16/7/7.
//
//

#import "WWSameSickVC.h"
#import "WWSameSickModel.h"
#import "WWSameSickCell.h"

@interface WWSameSickVC ()

// 记录用户订阅的内容
//@property (nonatomic, strong)NSMutableArray<NSIndexPath *> *records;

@end

@implementation WWSameSickVC

- (void)setSynSicks:(NSArray *)synSicks{

    if (synSicks == nil) {
        _synSicks = [WWSameSickModel synSicks];
    }else {
        _synSicks = synSicks;
    }
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // cell 注册
    [self.tableView registerClass:[WWSameSickCell class] forCellReuseIdentifier:@"WWSameSickCell"];
    
    self.navigationItem.title = @"并发病";
    self.navigationController.navigationBar.titleTextAttributes = @{
            NSForegroundColorAttributeName: [UIColor blackColor],
            NSFontAttributeName : [UIFont fontWithName:@"Helvetica" size:15.f]
                                                                    };
    
    // 添加确认item
    UIButton *sureBtn = [[UIButton alloc]init];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [sureBtn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    [sureBtn sizeToFit];
    UIBarButtonItem *sureItem = [[UIBarButtonItem alloc]initWithCustomView:sureBtn];
    
    self.navigationItem.rightBarButtonItem = sureItem;
    
    [sureBtn addTarget:self action:@selector(clickSure:) forControlEvents:UIControlEventTouchUpInside];
}

// MARK: 点击确定
- (void)clickSure:(UIButton *)btn{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    // 将整个数组传回
    if (self.sicksBlock) {
        self.sicksBlock(self.synSicks);
    }
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.synSicks.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WWSameSickCell *cell = [[WWSameSickCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WWSameSickCell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    WWSameSickModel *model = self.synSicks[indexPath.row];
    
    cell.model = model;

    cell.changeBlock = ^(){
        model.taped = !model.taped;
        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    };

    return cell;
}

- (void)tableView:tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

@end
